package nbcp.db.mongo

import org.slf4j.LoggerFactory
import nbcp.base.extend.*
import nbcp.base.utils.*
import nbcp.db.*
import nbcp.db.mongo.entity.*
import nbcp.db.mongo.table.*
import nbcp.db.mongo.*


class mor {
    companion object {
        val affectRowCount: Int
            get() = db.affectRowCount

        @JvmStatic
        val info = InfoGroup();

        @JvmStatic
        val shop = ShopGroup();

        @JvmStatic
        val admin = AdminGroup();

        @JvmStatic
        val system = SystemGroup();

        @JvmStatic
        fun getGroups(): Set<IDataGroup> = setOf(mor.system, mor.shop, mor.admin,mor.info)

        fun getCollection(collectionName: String): MongoBaseEntity<IMongoDocument>? {
            var groups = getGroups()

            var ret: BaseDbEntity? = null
            groups.any { group ->
                ret = group.getEntities().firstOrNull() { it.tableName == collectionName }

                return@any ret != null
            }

            return ret as MongoBaseEntity<IMongoDocument>?
        }

        val event = SpringUtil.getBean<MongoEventConfig>()
//
//        private val execAffectRows: ThreadLocal<Int> = ThreadLocal<Int>()
//
//        fun setMorExecAffectRows(n: Int) {
//            execAffectRows.set(n)
//        }
//
//        @JvmStatic
//        val affectRowCount: Int
//            get() {
//                return execAffectRows.get() ?: -1
//            }
//
//
//        @JvmStatic
//        val util = MongoUtil
        val logger = LoggerFactory.getLogger(this::class.java.declaringClass)

    }
}

